# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=augeas
pkgver=1.12.0
pkgrel=6
pkgdesc="A configuration editing tool"
url="http://augeas.net"
arch="all"
license="LGPL-2.1-or-later"
makedepends="autoconf automake libxml2-dev readline-dev libtool"
subpackages="$pkgname-static $pkgname-dev $pkgname-doc $pkgname-tests::noarch $pkgname-libs"
source="http://download.augeas.net/augeas-$pkgver.tar.gz
	fix-test.patch
	xsi-strerror.patch
	acf.aug
	awall.aug
	"

prepare() {
	default_prepare
	autoreconf -f -i
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--enable-static \
		--enable-shared \
		--disable-gnulib-tests
	make
	make tests
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	rm -rf "$pkgdir"/usr/lib/charset.alias
	# Upstream packaging mistake, this should never have been installed
	rm -f "$pkgdir"/usr/bin/dump

	local lens
	for lens in acf awall; do
		install -m 644 "$srcdir"/$lens.aug "$pkgdir"/usr/share/augeas/lenses
	done
}

tests() {
	pkgdesc="Tests for Augeas lenses"

	mkdir -p "$subpkgdir"/usr/share/augeas/lenses/dist/
	mv "$pkgdir"/usr/share/augeas/lenses/dist/tests \
		"$subpkgdir"/usr/share/augeas/lenses/dist/
}

libs() {
	pkgdesc="Libraries for augeas"
	replaces="augeas"

	mkdir -p "$subpkgdir"/usr/ "$subpkgdir"/usr/share/augeas/
	mv "$pkgdir"/usr/lib "$subpkgdir"/usr/
	mv "$pkgdir"/usr/share/augeas/lenses \
		"$subpkgdir"/usr/share/augeas/
}

static() {
	pkgdesc="Static libraries for Augeas"

	mkdir -p "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/lib/*.a "$subpkgdir"/usr/lib/
}

sha512sums="
4f61d4abbf338e915dfae212560d39792674bc757f05f500afa80c6170abc214ffb99cab2cf5bbd1c2338d11a6909e5fc3ff7112a2246fca69f7b39ac283da40  augeas-1.12.0.tar.gz
9768878b2f8710436ef1eba7868c22b5eff1d2d549434bf76aced72ebdb4af4f769ea638dedf42ac9b617aaa53d1a767ed6b18868dd0bb3cf72cb3889f6d933a  fix-test.patch
3d849cc223beb2a6e39f0082cb9fb8ca9f0683a91899e86c0e41672a7bc5691d156d1cb43cb55f4be29f56376ae0a54e48d61624c74d7a2d52beaffaa998c501  xsi-strerror.patch
74d728abdf4d3eebdeb3823c1d2588c214fd52734c8855fe3ddbfb6465d31c88d093df356e42effdd3dbdff1a62c52894c7aa840bd6ea8df4995c4f3aa53e919  acf.aug
fe83e70ddeced87fea4c4dbdfb90b7497bc5fd01b6b097f0f49c52894b4dc1d93cf217ae7aa98abeaba0a9f8e8e18a1d426b6c203b318afde9cd5164cbe604b1  awall.aug
"
